package cn.wxManage.user.controller;

import cn.common.common.model.ServerResponse;
import cn.wxManage.user.model.UserAddress;
import cn.wxManage.user.service.IAddressService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * Created by Zhang on 2019/1/31.
 */
@RestController
@RequestMapping("/userAddress")
@Api(value = "用户地址管理", description = "用户地址管理")
public class AddressController {
    @Autowired
    IAddressService iAddressService;

    @ApiOperation(value="新增/更新收获地址", notes="新增/更新收获地址(无ID为新增否则为更新)",produces = "application/json")
    @PostMapping(value = "/handleUserAddress")
    public ServerResponse<?> handleUserAddress(@RequestBody UserAddress userAddress){
        return iAddressService.handleUserAddress(userAddress);
    }

    @ApiOperation(value="删除收获地址", notes="删除收获地址",produces = "application/json")
    @GetMapping(value = "/deleteUserAddress")
    public ServerResponse<?> deleteUserAddress(@RequestParam("id") Integer id){
        return iAddressService.deleteUserAddress(id);
    }

    @ApiOperation(value="设置为默认收货地址", notes="删除收获地址",produces = "application/json")
    @GetMapping(value = "/setDefaultAddress")
    public ServerResponse<?> setDefaultAddress(@RequestParam("id") Integer id){
        return iAddressService.setDefaultAddress(id);
    }

    @ApiOperation(value="获取用户收获地址地址,默认显示第一个", notes="获取用户收获地址地址,默认显示第一个",produces = "application/json")
    @GetMapping(value = "/getUserAddress")
    public ServerResponse<?> getUserAddress(){
        return iAddressService.getUserAddress();
    }

    @ApiOperation(value="获取获取全国地址数据", notes="获取获取全国地址数据",produces = "application/json")
    @ApiImplicitParam(name = "fatherAdCode", value = "获取下一级行政区,为空则获取省级行政区",paramType ="query",dataType = "String")
    @GetMapping(value = "/getAddressList")
    public ServerResponse<?> getAddressList(@RequestParam("fatherAdCode") String fatherAdCode){
        return iAddressService.getAddressList(fatherAdCode);
    }
}
